package com.spark.common.upload.service;

import com.spark.common.upload.StorageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 阿里云OSS实现
 *
 * @author LYCHEE
 * @date 2025/3/13 10:12
 */
@Configuration
@ConditionalOnProperty(name = "upload.type", havingValue = "alioss")
public class AliOssStorageService implements StorageService {

    @Value("${upload.alioss.endpoint}")
    private String endpoint;
    @Value("${upload.alioss.access-key-id}")
    private String accessKeyId;
    @Value("${upload.alioss.access-key-secret}")
    private String accessKeySecret;
    @Value("${upload.alioss.bucket-name}")
    private String bucketName;

    @Override
    public String upload(MultipartFile file) throws IOException {
        return "";
    }

    @Override
    public String getFileUrl(String fileName) {
        return "";
    }

    //private OSS ossClient;
    //
    //@PostConstruct
    //public void init() {
    //    ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    //}
    //
    //@Override
    //public String upload(MultipartFile file) throws IOException {
    //    String fileName = FileUploadUtils.codingFileName(file);
    //    ossClient.putObject(bucketName, fileName, file.getInputStream());
    //    return getFileUrl(fileName);
    //}
    //
    //@Override
    //public String getFileUrl(String fileName) {
    //    return "https://" + bucketName + "." + endpoint + "/" + fileName;
    //}
    //
    //@PreDestroy
    //public void shutdown() {
    //    ossClient.shutdown();
    //}
}
